<?
	  layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<div class="col-lg-4">
	<div class="panel" style="height:100%; width:100%; overflow: auto;">
		<div class="panel-heading">范畴树形菜单</div>
		<div class="panel-heading" >
			<span class="subtitle">
				<button type="button" onclick="addUpdateThesauriWordCategory('0')" class="btn btn-primary btn-green"  style="width:80px;"
					id="savejiedian">新&nbsp;&nbsp;建</button>&nbsp;&nbsp;
				<button type="button"  class="btn btn-primary btn-green"  style="width:80px;"
					id="editjiedian">编&nbsp;&nbsp;辑</button>&nbsp;&nbsp;
				<button type="button" class="btn btn-primary btn-green"  style="width:80px;"
					id="deletejiedian">删&nbsp;&nbsp;除</button>
			</span>
		</div>
		<div class="panel-body">
			<ul id="tree" class="ztree" style="width:100%;height:405px;overflow: auto;"></ul>
		</div>
	</div>
</div>


<?} ?>

<script type="text/javascript">

	var classesId = window.parent.getZtreeClasses();
	var parentname=1;
	//树状结构
	$(function() {
		initTree();
	});

	var classid;
	var classname;
	function getclassname(){
		return classname;
	}
	function getclassid() {
		return classid;
	}
	function initTree(){
		$.ajax({
			type : "post",
			data : {
				"classesId":classesId
			},
			url : "./findallThesauriWordCategoryZTree.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠

	}
	function onClick(e, treeId, treeNode) {
		classid = treeNode.id;
		classname=treeNode.name;
		 if(treeNode.children==null)
        {
       			parentname=0;
        }else{
         		parentname=1;
        }
	}
	$("#deletejiedian").click(function () { 
		if(classid!=null){
			del(classid);
		}else{
			alert("请选中节点");
		}
	});
	function del(id) {
		if(parentname==0)
		{
			if (confirm("是否确认删除！！"))
			{
				$.ajax({
					type : "post",
					url : "./delThesauriWordCategory.do",
					data : {
						"id" : id
					},
					dataType : "json",
					success : function(data) {
						if(data.count==0){
							layer.msg('删除成功');
							initTree();
						}else{
							layer.msg('删除失败,与其它表关联不可删除！');
						}
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}
		}else{
			 alert("有子节点不允许删除");
		}
	}
	
	$("#editjiedian").click(function () { 
		if(classid!=null){
			addUpdateThesauriWordCategory(classid);
		}else{
			alert("请选中节点！！");
		}
	});
	var id;
	function getId(){
		return id;
	}
	function getclassesId(){
		return classesId;
	}
	function addUpdateThesauriWordCategory(lid) {
		id = lid;
		parent.layer.open({
			type : 2,
			title : '范畴添加编辑',
			scrollbar : false,
			shadeClose : true,
			move : false,
			area : [ '550px', '500px' ],
			fix : false, //不固定
			//maxmin : true,
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["word-thesauriWordCategory-zTreeAddEdit.html?winName="+window.name,'no'],
			yes: function(index,layer){
    	                   var iframeWin = parent.window[layer.find('iframe')[0]['name']];
    	                   iframeWin.Page();
    	              },
					cancel : function(index) {
					}
		});
	};
	
</script>